import { Injectable } from '@angular/core';
import { HttpClient, HttpParams } from '@angular/common/http';
import { Observable } from 'rxjs/internal/Observable';

import { ApiService } from './api.service';

@Injectable({
  providedIn: 'root'
})

export class ThreeLibsService {
  // 接口地址
  randomUserUrl = 'https://api.randomuser.me/';
  // randomUserUrl = 'http://10.0.2.83:8080/servers';

  constructor(private http: HttpClient, private apiservice: ApiService) { }

  getUsers(pageIndex: number = 1, pageSize: number = 10, sortField: string, sortOrder: string, genders: string[]): Observable<{}> {
    let params = new HttpParams()
      .append('page', `${pageIndex}`)
      .append('results', `${pageSize}`)
      .append('sortField', sortField)
      .append('sortOrder', sortOrder);
    genders.forEach(gender => {
      params = params.append('gender', gender);
    });
    console.log(typeof params);
    return this.http.get(`${this.randomUserUrl}`, { params });
  }
}
